package service.impl.v2;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.v2.ShowwindowVOMapper;
import model.CatVO;
import model.ShowwindowCatVO;
import model.ShowwindowCommentVO;
import model.ShowwindowPraiseVO;
import model.ShowwindowVO;
import service.v2.ShowwindowService;
@Service
public class ShowwindowServiceImpl implements ShowwindowService {
	@Autowired
	private ShowwindowVOMapper dao;

	public List<ShowwindowVO> getIndexList(ShowwindowVO showwindowVO) {
		return dao.getIndexList(showwindowVO);
	}

	public void processImg(List<ShowwindowVO> list, String screenwidth, int i) {
		if(list != null && list.size() != 0){
			for (ShowwindowVO vo : list) {
				if(!"".equals(vo.getGood_img())){
					vo.setGood_img(vo.getGood_img()+"?x-oss-process=image/resize,w_"+Integer.parseInt(screenwidth)/i);
				}
			}
		}
	}

	public int getTotal(ShowwindowVO showwindowVO) {
		return dao.getTotal(showwindowVO);
	}

	public List<ShowwindowVO> getList(ShowwindowVO showwindowVO) {
		return dao.getList(showwindowVO) ;
	}

	public int getWindowNumByMember(String member_id) {
		return dao.getWindowNumByMember(member_id) ;
	}

	public int getPraiseNumByMember(String member_id) {
		return dao.getPraiseNumByMember(member_id);
	}
	
	public List<ShowwindowCatVO> getWidowCatListByMember(String member_id) {
		List<ShowwindowCatVO> l = dao.getWidowCatListByMember(member_id);
		List<ShowwindowCatVO> list = new ArrayList<ShowwindowCatVO>();
		for (ShowwindowCatVO showwindowCatVO : l) {
			if(!("Y".equals(showwindowCatVO.getDefault_yn()) && showwindowCatVO.getNum() == 0)){
				list.add(showwindowCatVO);	
			}
		}
		return list;
	}

	public void processCatImg(List<ShowwindowCatVO> list, String screenwidth, int i) {
		if(list != null && list.size() != 0){
			for (ShowwindowCatVO showwindowCatVO : list) {
				if(showwindowCatVO.getGoodImgs() != null){
					List<String> imgs = new ArrayList<String>();
					for (String img : showwindowCatVO.getGoodImgs() ) {
						imgs.add(img+"?x-oss-process=image/resize,w_"+Integer.parseInt(screenwidth)/i);
					}
					showwindowCatVO.setGoodImgs(imgs);
				}
			}
		}
	}
	
	public void insertWindowCat(ShowwindowCatVO showwindowCatVO) {
		dao.insertWindowCat(showwindowCatVO);
	}
	public void updateWindowCat(ShowwindowCatVO showwindowCatVO) {
		dao.updateWindowCat(showwindowCatVO);
	}
	public void deleteWindowCat(ShowwindowCatVO showwindowCatVO) {
		//删除橱窗分类
		int num = dao.deleteWindowCat(showwindowCatVO);
		if(num == 1){
			//删除赞的统计
//			dao.deletePraise(showwindowCatVO);
			//删除评论
//			dao.deleteComment(showwindowCatVO);
			//删除橱窗分类关联表
			dao.deleteList(showwindowCatVO);
			//删除橱窗
			dao.deleteShowwindow(showwindowCatVO);
		}
	}

	public ShowwindowCatVO getWidowCatById(String cat_id) {
		return dao.getWidowCatById(cat_id);
	}
	public int getGoodnumByWindowCat(String cat_id) {
		return dao.getGoodnumByWindowCat(cat_id);
	}
	public List<ShowwindowVO> getShowwindowListByWindowCat(ShowwindowVO showwindowVO) {
		return dao.getShowwindowListByWindowCat(showwindowVO);
	}
	public List<CatVO> getGoodCatListByWindowCat(String cat_id) {
		return dao.getGoodCatListByWindowCat(cat_id);
	}
	public int getShowwindowListByWindowCatTotal(ShowwindowVO showwindowVO) {
		return dao.getShowwindowListByWindowCatTotal(showwindowVO);
	}
	
	public ShowwindowVO getWindowById(String window_id) {
		return dao.getWindowById(window_id);
	}
	public int getWindowCatNumByMember(String member_id) {
		return dao.getWindowCatNumByMember(member_id) ;
	}
	public int getCommentNumByShowwindow(String window_id) {
		return dao.getCommentNumByShowwindow(window_id);
	}
	public List<ShowwindowCommentVO> getCommentListByWindow(String window_id) {
		return dao.getCommentListByWindow(window_id);
	}
	public List<ShowwindowVO> getRecommandList(ShowwindowVO showwindowVO) {
		return dao.getRecommandList(showwindowVO);
	}
	public int getRecommandTotal(ShowwindowVO showwindowVO) {
		return dao.getRecommandTotal(showwindowVO);
	}
	public List<ShowwindowCatVO> getWindowCatList(ShowwindowCatVO showwindowCatVO) {
		return dao.getWindowCatList(showwindowCatVO);
	}
	public void updateShowwindow(ShowwindowVO showwindowVO) {
		dao.updateShowwindow(showwindowVO);
	}
	public void deleteShowwindow(ShowwindowVO showwindowVO) {
		//删除橱窗
		int num = dao.deleteShowwindowById(showwindowVO);
		if(num == 1){
			//删除赞的统计
//			dao.deletePraiseByWindow(showwindowVO);
			//删除评论
//			dao.deleteCommentByWindow(showwindowVO);
			//删除橱窗分类关联表
			dao.deleteListByWindow(showwindowVO);
		}
	}
	public List<ShowwindowCommentVO> getCommentList(ShowwindowVO showwindowVO) {
		return dao.getCommentList(showwindowVO);
	}
	public int checkGoodState(String good_id) {
		return dao.checkGoodState(good_id);
	}
	public int checkWindowCat(ShowwindowVO showwindowVO) {
		return dao.checkWindowCat(showwindowVO);
	}
	public void insertShowwindow(ShowwindowVO showwindowVO) {
		dao.insertShowwindow(showwindowVO);
	}
	public ShowwindowVO checkWindowGood(ShowwindowVO showwindowVO) {
		return dao.checkWindowGood(showwindowVO);
	}
	public void insertComment(ShowwindowCommentVO commentVO) {
		dao.insertComment(commentVO);
	}
	public ShowwindowPraiseVO checkPraiseByShowwindow(String window_id, String member_id) {
		return dao.checkPraiseByShowwindow( window_id,  member_id);
	}
	public void insertPraise(String showwindow_id, String member_id) {
		dao.insertPraise( showwindow_id,  member_id);
		dao.addPraiseNum(showwindow_id);
	}
	public void removePraise(String showwindow_id, String id) {
		dao.removePraise(id);
		dao.deletePraiseNum(showwindow_id);
	}
	public ShowwindowCommentVO getCommentById(String comment_id) {
		return dao.getCommentById(comment_id);
	}
	public void insertCommentReply(ShowwindowCommentVO commentVO) {
		dao.insertCommentReply(commentVO);
	}
	public void insertCommentReplyBack(ShowwindowCommentVO commentVO) {
		dao.insertCommentReplyBack(commentVO);
	}
	public void deleteCommentTop(String comment_id) {
		dao.deleteCommentTop(comment_id);
		dao.deleteCommentTopNoChild(comment_id);
	}
	public void deleteCommentReply(String comment_id) {
		dao.deleteCommentReply(comment_id);
	}
	public List<ShowwindowPraiseVO> getPraiseListByMember(ShowwindowPraiseVO praiseVO) {
		return dao.getPraiseListByMember(praiseVO);
	}
	public int getPraiseTotalByMember(ShowwindowPraiseVO praiseVO) {
		return dao.getPraiseTotalByMember(praiseVO);
	}
	public void updateUnreadPraise(ShowwindowPraiseVO praiseVO) {
		dao.updateUnreadPraise(praiseVO);
	}
	public List<ShowwindowCommentVO> getReplyListByMember(ShowwindowCommentVO commentVO) {
		return dao.getReplyListByMember(commentVO);
	}
	public int getReplyTotalByMember(ShowwindowCommentVO commentVO) {
		return dao.getReplyTotalByMember(commentVO);
	}
	public void updateUnreadReply(ShowwindowCommentVO commentVO) {
		dao.updateUnreadReply(commentVO);
	}

	public int selectDzNum(String member_id) {
		return dao.selectDzNum(member_id);

	}
	
	public ShowwindowCatVO getDefaultWindowCat(String member_id) {
		return dao.getDefaultWindowCat(member_id);
	}
	public void insertDefaultWindowCat(String member_id) {
		dao.insertDefaultWindowCat(member_id);
	}
	public void updataCatWindowListShareTimes(String cat_id) {
		dao.updataCatWindowListShareTimes(cat_id);
	}

	public void updataWindowDetailShareTimes(String window_id) {
		dao.updataWindowDetailShareTimes(window_id);
	}

	public String getcommunityMsg(String member_id) {
		String community_msg = "";
		
		ShowwindowCatVO dz_one = dao.getDzOneVo(member_id);
		ShowwindowCatVO pl_one = dao.getPlOneVo(member_id);
		if(dz_one ==null && pl_one ==null){
			
		}else{
			if(dz_one !=null && pl_one ==null){
				community_msg ="您收到了新的点赞";
			}else if(dz_one ==null && pl_one !=null){
				community_msg ="您收到了新的评论";
			}else{
				int dz_millisecond = dao.getDzMillisecond(member_id);
				int pl_millisecond = dao.getPlMillisecond(member_id);
				
				if(dz_millisecond>pl_millisecond){
					community_msg ="您收到了新的点赞";
				}else{
					community_msg ="您收到了新的评论";
				}
			}
		}
		
		
		return community_msg;
	}
	
	public void updatePraiseVODelete(String showwindow_id, String id) {
		dao.updatePraiseVODelete(id);
		dao.addPraiseNum(showwindow_id);
	}
	
	public void updateCommentRead(String comment_id) {
		dao.updateCommentRead(comment_id);
	}
	public void updateCommentReadAll(String member_id) {
		dao.updateCommentReadAll(member_id);
	}
	
	public void updatePraiseRead(String praise_id) {
		dao.updatePraiseRead(praise_id);
	}
}
